package com.bbu.javaexam.controller;

import com.bbu.javaexam.domain.Admin;
import com.bbu.javaexam.domain.RespData;
import com.bbu.javaexam.service.AdminService;
import com.bbu.javaexam.util.RespDataHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Alex
 * @version 1.0.0
 * @ClassName AdminController.java
 * @Description TODO
 */
@RestController
public class AdminController {
    @Autowired
    private AdminService adminService;

    @GetMapping("/admins")
    public RespData findAll() {
        return RespDataHandler.success(adminService.findAll());
    }

    @GetMapping("/admin/{adminId}")
    public RespData findById(@PathVariable("adminId") Integer adminId) {
        return RespDataHandler.success(adminService.findById(adminId));
    }

    @DeleteMapping("/admin/{adminId}")
    public RespData deleteById(@PathVariable("adminId") Integer adminId) {
        return RespDataHandler.success(adminService.deleteById(adminId));
    }

    @PutMapping("/admin/{adminId}")
    public RespData update(@PathVariable("adminId") Integer adminId, Admin admin) {
        return RespDataHandler.success(adminService.update(admin));
    }

    @PostMapping("/admin")
    public RespData add(Admin admin) {
        return RespDataHandler.success(adminService.add(admin));
    }
}
